package com.sgb.kjwl.view.ui.adapter.shopping;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.ShopGoodsInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class ShopMateriaAdapter extends BaseRecycleAdapter<ShopGoodsInfoEntity> {

    private TextView priceView;
    private ImageView imageView;
    private TextView cuPrice;
    private RequestOptions options;
    private TextView tvSpec;
    private ImageView img_cx;
    public ShopMateriaAdapter(Context context, List<ShopGoodsInfoEntity> datas) {
        super(context, R.layout.item_shop_macheine_list3, datas);

        options = new RequestOptions()
                .placeholder(R.drawable.null_img_list);//图片加载出来前，显示的图片
    }

    @Override
    public void convert(ItemViewHolder holder, ShopGoodsInfoEntity shopGoodsInfoEntity) {
        holder.setBinding(BR.viewModel, shopGoodsInfoEntity);
        imageView = holder.itemView.findViewById(R.id.img_view);
        priceView = holder.itemView.findViewById(R.id.price_view);
        img_cx = holder.getItem().findViewById(R.id.img_cx);
        cuPrice = holder.getItem().findViewById(R.id.cu_price);
        tvSpec = holder.getItem().findViewById(R.id.tv_spec);
        priceView.setText(shopGoodsInfoEntity.getPrice());
        Glide.with(context).load(shopGoodsInfoEntity.getImage()).apply(options).into((imageView));
        if (shopGoodsInfoEntity.getPromoteStatus() == 2) {
            img_cx.setVisibility(View.VISIBLE);
            cuPrice.setVisibility(View.VISIBLE);
            tvSpec.setVisibility(View.VISIBLE);
            cuPrice.setText(shopGoodsInfoEntity.getPromotePrice());
            cuPrice.setTextColor(context.getResources().getColor(R.color.new_org));
            priceView.setTextColor(context.getResources().getColor(R.color.color_666666));
            priceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            img_cx.setVisibility(View.GONE);
            cuPrice.setVisibility(View.GONE);
            tvSpec.setVisibility(View.GONE);
            priceView.setTextColor(context.getResources().getColor(R.color.new_org2));
            priceView.getPaint().setFlags(priceView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
        }
    }
}
